
/*    HTTP Host:  c.static.ak.fbcdn.net                                        */
/*    Generated:  August 10th 2009 1:10:39 PM PDT                              */
/*      Machine:  10.16.140.110                                                */
/*       Source:  Backing Store                                                */
/*     Location:  js/homefeed.js h:5bipl5nx                                    */
/*       Locale:  nu_ll                                                        */
/*         Path:  js/homefeed.js                                               */
function HomeFeed(newestStoryTime, oldestStoryTime, autoRefresh, tabset, tabIds, nonTabId, logMode, showLogModeOption, embeddedWidget) {
	HomeFeed.instance = this;
	this.resetState();
	this.oldestStoryTime = oldestStoryTime || 0;
	this.newestStoryTime = newestStoryTime || 0;
	this.lastNewestStoryTime = 0;
	this.lastLocalNewestTime = (new Date()).getTime();
	this.cdnTimeSyncFrequency = 0;
	this.submenuShown = false;
	this.requestCount = 0;
	this.akamaiRequestCount = 0;
	this.akamaiTotalLatency = 0;
	this.akamaiTotalStories = 0;
	this.sendTime = 0;
	this.requestLastSeen = 0;
	this.currentDelay = HomeFeed.defaultDelay;
	this.supportsCdn = false;
	this.canSupportCdn = true;
	this.logModeOptionShown = showLogModeOption;
	this.logMode = logMode;
	this.resetRefreshCount();
	this.setAutoRefresh(autoRefresh);
	this.tabset = tabset;
	this.nonTabId = nonTabId;
	this.tabIds = tabIds;
	this.timerHandle = null;
	this.newStoriesClass = null;
	this.widgetAppId = null;
	this.widgetStreamId = null;
	this.widgetApiKey = null;
	this.feedbackTargets = {};
	this.gmtOffsetMinutes = null;
	this.liveCommentUpdating = false;
	this.maxStoriesInDom = null;
	this.skipCDNTillNextStory = false;
	this.showLoggedOutError = true;
	this.embeddedWidget = embeddedWidget;
	this.widgetLocale = null;
	this.minimumReloadFrequency = 0;
	if (this.embeddedWidget) {
		LinkController.registerHandler(HomeFeed.newWindowLinkController, null, true);
	}
	PageTransitions.registerHandler(HomeFeed.pageTransitionHandler);
}
HomeFeed.getInstance = function () {
	return HomeFeed.instance;
};
HomeFeed.defaultDelay = 10 * 1000;
HomeFeed.inactiveDelay = 300 * 1000;
HomeFeed.defaultRefreshes = 90;
HomeFeed.intermittentDelay = 7 * 1000;
HomeFeed.LOC_REPLACE = 1;
HomeFeed.LOC_PREPEND = 2;
HomeFeed.LOC_APPEND = 3;
HomeFeed.TAB_TOP_STORIES = 1;
HomeFeed.TAB_LIVE_FEED = 2;
HomeFeed.TAB_STATUS = 3;
HomeFeed.TAB_PHOTOS = 4;
HomeFeed.TAB_POSTED_ITEMS = 5;
HomeFeed.TAB_LIVEWIDGET_FRIENDS = 7;
HomeFeed.TAB_LIVEWIDGET_EVERYONE = 8;
HomeFeed.pageTransitionHandler = function (uri) {
	var inst = HomeFeed.getInstance();
	if (uri.getPath() == "/home.php" || uri.getPath() == "/widgets/livefeed.php") {
		var query = uri.getQueryData();
		if (inst) {
			inst.clearFeedbackTargets();
			if ("logged_out" in query || "login" in query) {
				return false;
			}
			if ("tab" in query) {
				inst.resetState();
				inst.setTab(query.tab);
				if (query.tab == HomeFeed.TAB_LIVE_FEED) {
					inst.setAutoRefresh(true);
					inst.showLogModeOption(true);
					inst.refreshLogMode(inst.logMode);
				} else {
					if (query.tab == HomeFeed.TAB_LIVEWIDGET_FRIENDS || query.tab == HomeFeed.TAB_LIVEWIDGET_EVERYONE) {
						inst.setAutoRefresh(true);
					} else {
						inst.refreshLogMode(false);
					}
				}
				if (inst.tabset) {
					inst.tabset.selectTab(inst.tabIds[query.tab]);
				}
				if (inst.nonTabId) {
					CSS.removeClass($(inst.nonTabId), "HomeFeed_selected");
				}
				inst.refresh(HomeFeed.LOC_REPLACE, {"new_request":1}, true, true);
				return true;
			} else {
				var app = query.app_id || 0;
				var stream_id = query.stream_id || 0;
				var friendList = query.fl || 0;
				if (app || friendList) {
					if (inst.tabset) {
						inst.tabset.unselect();
					}
					if (inst.nonTabId) {
						CSS.addClass($(inst.nonTabId), "HomeFeed_selected");
					}
					inst.resetState();
					inst.refreshLogMode(false);
					inst.showLogModeOption(false);
					if (app) {
						inst.setApp(app);
					}
					if (stream_id) {
						inst.setWidgetStreamId(stream_id);
					}
					if (friendList) {
						inst.setFriendList(friendList);
					}
					inst.refresh(HomeFeed.LOC_REPLACE, {"new_request":1}, true, true);
					return true;
				}
			}
		}
	}
	return false;
};
HomeFeed.newWindowLinkController = function (link) {
	var uri = new URI(link.href);
	var path = uri.getPath();
	if (path != "/home.php" && path != "/widgets/livefeed.php" && path != "/logout.php") {
		window.open(uri);
		return false;
	}
	return true;
};
HomeFeed.setDefaultRefreshes = function (refreshes) {
	HomeFeed.defaultRefreshes = refreshes;
};
HomeFeed.prototype.openLiveWidgetLoginPopup = function (loginUrl) {
	if (!loginUrl) {
		loginUrl = "/login.php";
	}
	var uri = new URI(loginUrl);
	uri.addQueryData({"api_key":this.widgetApiKey, "fbconnect":1, "iframe_widget":1});
	var target = "iframe_widget_login";
	var args = "toolbar=0,status=0,resizable=0,width=500,height=430";
	window.open(uri.toString(), target, args);
};
HomeFeed.prototype.resetState = function () {
	this.apps = [];
	this.friendLists = [];
	this.tabId = null;
	this.oldestStoryTime = 0;
	this.newestStoryTime = 0;
	this.lastNewestStoryTime = 0;
	if (this.timerSet) {
		clearTimeout(this.timerHandle);
	}
	this.timerSet = false;
	this.timerHandle = null;
	this.storyQueue = [];
	this.queueTimerHandle = null;
	this.newStoriesClass = null;
	this.supportsCdn = false;
	this.clearStoryQueue();
	this.resetRefreshCount();
	this.setAutoRefresh(false);
	return this;
};
HomeFeed.prototype.resetRefreshCount = function () {
	this.currentRefreshes = HomeFeed.defaultRefreshes;
	return this;
};
HomeFeed.prototype.refreshLogMode = function (logModeStatus) {
	var wrapperEl = $("newsfeed_wrapper");
	if (logModeStatus) {
		CSS.addClass(wrapperEl, "log_mode");
		CSS.removeClass(wrapperEl, "full_mode");
	} else {
		CSS.addClass(wrapperEl, "full_mode");
		CSS.removeClass(wrapperEl, "log_mode");
	}
	return this;
};
HomeFeed.prototype.addApp = function (appId) {
	if (appId) {
		if (this.apps.indexOf(appId) == -1) {
			this.apps.push(appId);
		}
	}
	return this;
};
HomeFeed.prototype.removeApp = function (appId) {
	if (this.apps.indexOf(appId) != -1) {
		this.apps.remove(appId);
	}
	return this;
};
HomeFeed.prototype.clearApps = function () {
	if (this.apps.length > 0) {
		this.apps = [];
	}
	return this;
};
HomeFeed.prototype.setApp = function (appId) {
	this.clearApps().addApp(appId);
	return this;
};
HomeFeed.prototype.setWidgetApp = function (appId) {
	this.widgetAppId = appId;
	return this;
};
HomeFeed.prototype.setWidgetStreamId = function (streamId) {
	this.widgetStreamId = streamId;
	return this;
};
HomeFeed.prototype.setWidgetApiKey = function (widgetApiKey) {
	this.widgetApiKey = widgetApiKey;
	return this;
};
HomeFeed.prototype.addFriendList = function (flId) {
	if (this.friendLists.indexOf(flId) == -1) {
		this.friendLists.push(flId);
	}
	return this;
};
HomeFeed.prototype.removeFriendList = function (flId) {
	if (this.friendLists.indexOf(flId) != -1) {
		this.friendLists.remove(flId);
	}
	return this;
};
HomeFeed.prototype.clearFriendLists = function () {
	this.friendLists = [];
	return this;
};
HomeFeed.prototype.setFriendList = function (flId) {
	this.clearFriendLists().addFriendList(flId);
	return this;
};
HomeFeed.prototype.setTab = function (tabId) {
	this.tabId = tabId;
	return this;
};
HomeFeed.prototype.getTab = function () {
	return this.tabId;
};
HomeFeed.prototype.clearTab = function () {
	this.tabId = null;
	return this;
};
HomeFeed.prototype.setLiveCommentUpdating = function (enabled) {
	this.liveCommentUpdating = enabled;
	return this;
};
HomeFeed.prototype.setWidgetLocale = function (widgetLocale) {
	this.widgetLocale = widgetLocale;
	return this;
};
HomeFeed.prototype.setReloadVersion = function (reloadVersion) {
	this.reloadVersion = reloadVersion;
	return this;
};
HomeFeed.prototype.setMinimumReloadFrequency = function (minSeconds) {
	this.minimumReloadFrequency = minSeconds;
	return this;
};
HomeFeed.prototype.setGmtOffsetMinutes = function (offset) {
	this.gmtOffsetMinutes = offset;
	return this;
};
HomeFeed.prototype.registerfeedbackTarget = function (itemId, targetFbid, actor, typeId, assocObjId, commentsHash, hasHiddenComments) {
	var feedbackTarget = {"item_id":itemId, "target_fbid":targetFbid, "actor":actor, "type_id":typeId, "assoc_obj_id":assocObjId, "comments_hash":commentsHash, "has_hidden_comments":hasHiddenComments};
	var key = itemId + ":" + targetFbid;
	this.feedbackTargets[key] = feedbackTarget;
	return this;
};
HomeFeed.prototype.clearFeedbackTargets = function () {
	this.feedbackTargets = {};
	return this;
};
HomeFeed.prototype.updatefeedbackTargetHash = function (itemId, targetFbid, newCommentsHash) {
	var key = itemId + ":" + targetFbid;
	if (this.feedbackTargets[key]) {
		this.feedbackTargets[key]["comments_hash"] = newCommentsHash;
	}
	return this;
};
HomeFeed.prototype.updateFeedbackTargetHiddenStatus = function (itemId, targetFbid, hasHidden) {
	var key = itemId + ":" + targetFbid;
	if (this.feedbackTargets[key]) {
		this.feedbackTargets[key]["has_hidden_comments"] = hasHidden;
	}
	return this;
};
HomeFeed.prototype.updateCommentsFromPayload = function (comments_payload, source) {
	for (var i = 0; i < comments_payload.length; i++) {
		var modified_target = comments_payload[i];
		var item_id = modified_target.item_id;
		var target_fbid = modified_target.target_fbid;
		feedcomment_sync_with_markup(target_fbid, item_id, modified_target.markup, modified_target.comment_count, source);
		this.updatefeedbackTargetHash(item_id, target_fbid, modified_target.comments_hash);
	}
};
HomeFeed.prototype.getFeedbackTargets = function () {
	return this.feedbackTargets;
};
HomeFeed.prototype.showSubmenu = function (text) {
	set_inner_html($("newsfeed_submenu_content"), text);
	if (!this.submenuShown) {
		$("newsfeed_submenu").removeClass("hidden_elem");
	}
	this.submenuShown = true;
	this.refreshLogModeOption();
	return this;
};
HomeFeed.prototype.hideSubmenu = function () {
	if (this.submenuShown) {
		$("newsfeed_submenu").addClass("hidden_elem");
	}
	this.submenuShown = false;
	return this;
};
HomeFeed.prototype.showLogModeOption = function (status) {
	this.logModeOptionShown = status;
	return this;
};
HomeFeed.prototype.refreshLogModeOption = function () {
	var logModeOptionEl = ge("newsfeed_submenu_log_mode_option");
	var logModeSelectedClass = "log_mode_selected";
	var newsfeed_submenu_headlines_only = ge("newsfeed_submenu_headlines_only");
	var newsfeed_submenu_full_stories = ge("newsfeed_submenu_full_stories");
	if (newsfeed_submenu_headlines_only && newsfeed_submenu_full_stories) {
		if (this.logMode) {
			newsfeed_submenu_headlines_only.addClass(logModeSelectedClass);
			newsfeed_submenu_full_stories.removeClass(logModeSelectedClass);
		} else {
			newsfeed_submenu_headlines_only.removeClass(logModeSelectedClass);
			newsfeed_submenu_full_stories.addClass(logModeSelectedClass);
		}
	}
	if (logModeOptionEl) {
		if (this.logModeOptionShown) {
			logModeOptionEl.removeClass("hidden_elem");
		} else {
			logModeOptionEl.addClass("hidden_elem");
		}
	}
	return this;
};
HomeFeed.prototype.loadOlder = function () {
	var extraData = {"oldest":this.oldestStoryTime};
	this.refresh(HomeFeed.LOC_APPEND, extraData, true, false);
	return this;
};
HomeFeed.prototype.loadNewer = function () {
	var extraData = {"newest":this.newestStoryTime};
	if (this.canSupportCdn && this.supportsCdn) {
		if (this.newestStoryTime == this.lastNewestStoryTime) {
			var now = (new Date()).getTime();
			var delta = parseInt((now - this.lastLocalNewestTime) / 1000);
			this.newestStoryTime += delta;
			this.lastLocalNewestTime = now;
		}
		this.lastNewestStoryTime = this.newestStoryTime;
	}
	this.refresh(HomeFeed.LOC_PREPEND, extraData, false, false);
	return this;
};
HomeFeed.prototype.setCdnTimeSyncFrequency = function (frequency) {
	this.cdnTimeSyncFrequency = parseInt(frequency);
	return this;
};
HomeFeed.prototype.setSkipCDNTillNextStory = function (setting) {
	this.skipCDNTillNextStory = setting;
	return this;
};
HomeFeed.prototype.setCanSupportCdn = function (canSupportCdn) {
	this.canSupportCdn = canSupportCdn;
	return this;
};
HomeFeed.prototype.isCdnEnabled = function () {
	var enabled = this.canSupportCdn && this.supportsCdn && !this.skipCDNTillNextStory;
	return enabled;
};
HomeFeed.prototype.syncNewestStoryTime = function () {
	var postData = {};
	postData["widget_app_id"] = this.widgetAppId;
	postData["widget_stream_id"] = this.widgetStreamId;
	postData["ak_r_ct"] = this.akamaiRequestCount;
	if (this.akamaiRequestCount > 0) {
		postData["ak_av_lat"] = parseInt(this.akamaiTotalLatency / this.akamaiRequestCount);
		postData["ak_av_stor"] = parseInt(this.akamaiTotalStories / this.akamaiRequestCount);
	}
	postData["min_reload_freq"] = this.minimumReloadFrequency;
	if (this.tabId == HomeFeed.TAB_LIVEWIDGET_EVERYONE && this.widgetLocale) {
		postData["locale"] = this.widgetLocale;
	}
	this.akamaiRequestCount = 0;
	this.akamaiTotalLatency = 0;
	this.akamaiTotalStories = 0;
	var updateTimeHandler = function (asyncReponse) {
		var payload = asyncReponse.getPayload();
		if (payload && "lastestTime" in payload) {
			this.newestStoryTime = parseInt(payload["lastestTime"]);
			this.lastLocalNewestTime = (new Date()).getTime();
		}
		if (payload && "cdnSyncFrequency" in payload) {
			this.setCdnTimeSyncFrequency(payload["cdnSyncFrequency"]);
		}
	};
	var noopHandler = function (asyncReponse) {
	};
	var async = new AsyncRequest().setReadOnly(true).setOption("retries", 0).setMethod("GET").setData(postData).setHandler(bind(this, updateTimeHandler)).setErrorHandler(noopHandler).setTransportErrorHandler(noopHandler).setURI("/ajax/live_feed_last_action.php").send();
};
HomeFeed.prototype.loadMore = function (story_keys) {
	var extraData = {"story_keys":story_keys};
	this.refresh(HomeFeed.LOC_APPEND, extraData, false, false);
	return this;
};
HomeFeed.prototype.autoRefreshFire = function () {
	this.timerSet = false;
	this.timerHandle = null;
	if (!this.autoRefresh) {
		return;
	}
	this.loadNewer();
};
HomeFeed.prototype.autoRefreshHandler = function () {
	if (!this.autoRefresh || this.timerSet || !this.currentDelay) {
		return;
	}
	var delay = this.currentDelay;
	if (this.currentRefreshes <= 0) {
		delay = HomeFeed.inactiveDelay;
	} else {
		this.currentRefreshes--;
	}
	if (!this.supportsCdn) {
		delay = parseInt(delay * (0.75 + 0.5 * Math.random()));
	}
	this.timerSet = true;
	this.timerHandle = setTimeout(this.autoRefreshFire.bind(this), delay);
};
HomeFeed.prototype.setAutoRefresh = function (status) {
	if (!status && this.timerSet) {
		clearTimeout(this.timerHandle);
		this.timerHandle = null;
	}
	this.autoRefresh = status;
	this.autoRefreshHandler();
	return this;
};
HomeFeed.prototype.refresh = function (location, extraData, showIndicator, isTransition) {
	var isAutoRefresh = this.autoRefresh;
	location = location || HomeFeed.LOC_REPLACE;
	showIndicator = (showIndicator === undefined) ? true : showIndicator;
	isTransition = isTransition || false;
	var animOnDone = function (animObj) {
		if (showIndicator && !ge("feed_loading_image")) {
			var loadEl = document.createElement("img");
			loadEl.src = "/images/loaders/indicator_blue_large.gif";
			loadEl.id = "feed_loading_image";
			var wrapperEl = $("newsfeed_wrapper");
			if (location == HomeFeed.LOC_APPEND) {
				wrapperEl.parentNode.appendChild(loadEl);
			} else {
				wrapperEl.parentNode.insertBefore(loadEl, wrapperEl);
			}
		}
		this.requestCount++;
		var requestNumber = this.requestCount;
		var loadStoriesHandler = function (asyncResponse) {
			var payload = asyncResponse.getPayload();
			if (payload) {
				if ("newDelay" in payload) {
					this.currentDelay = payload.newDelay;
				}
				if ("newRefreshCount" in payload) {
					HomeFeed.defaultRefreshes = payload.newRefreshCount;
				}
				if ("newStoriesClass" in payload) {
					this.newStoriesClass = payload.newStoriesClass;
				}
				this.supportsCdn = false;
				if ("enableCdn" in payload && this.canSupportCdn) {
					this.supportsCdn = payload.enableCdn;
					if (this.requestCount && this.cdnTimeSyncFrequency && (this.requestCount % this.cdnTimeSyncFrequency) == 0) {
						this.syncNewestStoryTime(false);
					}
					if ("n_stories" in payload) {
						this.akamaiTotalStories += payload.n_stories;
					}
				}
				if (this.sendTime) {
					this.akamaiTotalLatency += (new Date()).getTime() - this.sendTime;
					this.sendTime = 0;
				}
				if (requestNumber != this.requestCount) {
					return;
				}
				this.removeLoadingImage();
				this.removeErrorMessage();
				this.updateLastSeen(requestNumber);
				var wrapperEl = $("newsfeed_wrapper");
				var html = payload["html"] || null;
				var stories = payload["stories"] || [];
				if (html || (stories && stories.length)) {
					this.setSkipCDNTillNextStory(false);
					if ("newestStoryTime" in payload && payload["newestStoryTime"] > this.newestStoryTime) {
						this.newestStoryTime = payload["newestStoryTime"];
						this.lastLocalNewestTime = (new Date()).getTime();
					}
					if ("lastestTime" in payload) {
						this.lastestTime = parseInt(payload["lastestTime"]);
					}
					if ("oldestStoryTime" in payload && (this.oldestStoryTime == 0 || payload["oldestStoryTime"] < this.oldestStoryTime)) {
						this.oldestStoryTime = payload["oldestStoryTime"];
					}
					if ("submenuText" in payload) {
						this.showSubmenu(payload.submenuText);
					} else {
						this.hideSubmenu();
					}
					this.refreshLogModeOption();
					this.removeStoryStatusMessage();
					if (stories && stories.length) {
						this._addStoriesToQueue(stories);
					} else {
						if (html) {
							this.updateStoriesHTML(html, this.newStoriesClass, location);
						}
					}
				}
				if ("storiesCount" in payload && payload["storiesCount"]) {
					var standardStatus = ge("standard_status");
					if (standardStatus) {
						hide(standardStatus);
					}
				}
				if ("livefeedBottomMessage" in payload) {
					var text = payload["livefeedBottomMessage"];
					var bottom_message = ge("livefeed_bottom_message");
					if (bottom_message) {
						bottom_message.setContent(text);
					}
					if (text.length >= 70) {
						CSS.addClass(bottom_message, "long_bottom_message");
					} else {
						CSS.removeClass(bottom_message, "long_bottom_message");
					}
					var livefeed = ge("livefeed_main_item");
					if (livefeed) {
						if (text.length > 0) {
							CSS.addClass(livefeed, "with_bottom_message");
						} else {
							CSS.removeClass(livefeed, "with_bottom_message");
						}
					}
				}
				if ("modified_comments" in payload) {
					var sources = feedcomment_get_feedback_sources();
					var source = sources["FEEDBACK_SOURCE_NEWS_FEED"];
					this.updateCommentsFromPayload(payload.modified_comments, source);
				}
				if ("maxStoriesInDom" in payload && payload.maxStoriesInDom) {
					this.maxStoriesInDom = payload.maxStoriesInDom;
					this.truncateStories();
				}
				if (this.reloadVersion && "reloadVersion" in payload && payload["reloadVersion"] > this.reloadVersion && "reloadRangeInSeconds" in payload) {
					this.setReloadVersion(payload["reloadVersion"]);
					var reloadTime = Math.max(10000, Math.random() * 1000 * payload["reloadRangeInSeconds"]);
					setTimeout(function () {
						window.location.reload();
					}, reloadTime);
				}
			}
			if (isAutoRefresh) {
				this.autoRefreshHandler();
			}
		}.bind(this);
		if (location != HomeFeed.LOC_PREPEND) {
			var bottomEl = ge("feed_bottom_links");
			if (bottomEl) {
				bottomEl.parentNode.removeChild(bottomEl);
			}
		}
		var postData = (typeof extraData == "object") ? extraData : {};
		if (this.apps.length) {
			postData["apps"] = this.apps;
		}
		if (this.friendLists.length) {
			postData["fl"] = this.friendLists;
		}
		if (this.tabId) {
			postData["tab"] = this.tabId;
		}
		if (this.minimumReloadFrequency) {
			postData["min_reload_freq"] = this.minimumReloadFrequency;
		}
		var method = "GET";
		if (this.feedbackTargets && this.liveCommentUpdating) {
			var feedbackTargetArray = values(this.feedbackTargets);
			if (feedbackTargetArray.length) {
				postData["feedback_targets"] = JSON.encode(feedbackTargetArray);
				method = "POST";
			}
		}
		if (this.widgetAppId) {
			postData["widget_app_id"] = this.widgetAppId;
		}
		if (this.widgetStreamId) {
			postData["widget_stream_id"] = this.widgetStreamId;
		}
		if (this.tabId == HomeFeed.TAB_LIVEWIDGET_EVERYONE && this.widgetLocale) {
			postData["locale"] = this.widgetLocale;
		}
		if (this.reloadVersion) {
			postData["reload_version"] = this.reloadVersion;
		}
		if (this.gmtOffsetMinutes != null) {
			postData["gmt_offset_minutes"] = this.gmtOffsetMinutes;
		}
		var async = new AsyncRequest().setReadOnly(true).setOption("retries", 0).setMethod(method).setData(postData).setHandler(loadStoriesHandler).setErrorHandler(bind(this, this._refreshErrorHandler, location, requestNumber)).setTransportErrorHandler(bind(this, this._refreshErrorHandler, location, requestNumber)).setFinallyHandler(function () {
			if (isTransition) {
				PageTransitions.transitionComplete();
			}
		});
		if (this.isCdnEnabled()) {
			this.akamaiRequestCount++;
			async.setOption("jsonp", true);
			async.setOption("nectar", false);
			postData["jsonp"] = true;
			async.setURI("http://livefeed.facebook.com/ajax/feed.php");
			this.sendTime = (new Date()).getTime();
		} else {
			async.setURI("/ajax/feed.php");
		}
		if (this.tabset) {
			async.setContextData("src_tab_name", this.tabset.lastSelected).setContextData("dst_tab_name", this.tabset.selectedId).setContextData("nectar_isaction", true);
		}
		async.send();
	}.bind(this);
	var wrapperEl = $("newsfeed_wrapper");
	if (location == HomeFeed.LOC_REPLACE) {
		set_inner_html(wrapperEl, "");
	}
	animOnDone();
};
HomeFeed.prototype.truncateStories = function () {
	if (this.maxStoriesInDom) {
		var wrapperEl = $("newsfeed_wrapper");
		var feedItems = DOM.scry(wrapperEl, "div.feed_item");
		for (var i = feedItems.length - 1; i >= this.maxStoriesInDom; i--) {
			var feedItem = feedItems[i];
			feedItem.parentNode.removeChild(feedItem);
		}
		var targetKeys = keys(this.feedbackTargets);
		var targetsToTrim = targetKeys.length - this.maxStoriesInDom;
		for (var i = 0; i < targetsToTrim; i++) {
			var key = targetKeys[i];
			delete this.feedbackTargets[key];
		}
	}
};
HomeFeed.prototype.removeLoadingImage = function () {
	this._removeElementWithId("feed_loading_image");
	return this;
};
HomeFeed.prototype.removeErrorMessage = function () {
	this._removeElementWithId("feed_error_wrapper");
	return this;
};
HomeFeed.prototype._removeElementWithId = function (id) {
	var el = ge(id);
	if (el) {
		el.parentNode.removeChild(el);
	}
	return this;
};
HomeFeed.prototype.updateLastSeen = function (requestNumber) {
	if (this.requestLastSeen < requestNumber) {
		this.requestLastSeen = requestNumber;
	}
};
HomeFeed.prototype._addStoriesToQueue = function (stories) {
	this.storyQueue = this.storyQueue.concat(stories);
	this.startStoryQueue();
};
HomeFeed.prototype.startStoryQueue = function () {
	if (this.queueTimerHandle) {
		return;
	}
	this._handleStoryQueue();
};
HomeFeed.prototype.clearStoryQueue = function () {
	if (this.queueTimerHandle) {
		clearTimeout(this.queueTimerHandle);
	}
	this.storyQueue = [];
};
HomeFeed.prototype._handleStoryQueue = function () {
	if (this.storyQueue.length) {
		var len = this.storyQueue.length;
		var storiesToShow = Math.ceil(len / 3);
		var stories = this.storyQueue.splice(0, storiesToShow);
		var html = stories.join("");
		var newDiv = document.createElement("div");
		set_inner_html(newDiv, html);
		newDiv.style.overflow = "hidden";
		CSS.addClass(newDiv, this.newStoriesClass);
		this.updateWrapper(HomeFeed.LOC_PREPEND, newDiv, true);
		this.queueTimerHandle = null;
		if (this.storyQueue.length > 0) {
			this.queueTimerHandle = setTimeout(this._handleStoryQueue.bind(this), HomeFeed.intermittentDelay);
		}
	}
};
HomeFeed.prototype._refreshErrorHandler = function (location, requestNumber, response) {
	if (requestNumber != this.requestCount) {
		return;
	}
	this.removeLoadingImage();
	this.updateLastSeen(requestNumber);
	var error = response.getError();
	var loginMarkup;
	if (this.embeddedWidget) {
		var onclick = "HomeFeed.getInstance().openLiveWidgetLoginPopup();";
		loginMarkup = "<a href=\"#\" onClick=\"" + onclick + "\">" + _tx("log in") + "</a>";
	} else {
		loginMarkup = "<a href=\"" + login_url + "\">" + _tx("log in") + "</a>";
	}
	if (error == kError_Async_NotLoggedIn) {
		var title = _tx("Feed Error");
		var msg = _tx("Your session has timed out. Please {login}.", {"login":loginMarkup});
		new ErrorDialog().showError(title, msg);
		return;
	}
	if (location == HomeFeed.LOC_PREPEND) {
		return;
	}
	var errorDiv = document.createElement("div");
	errorDiv.id = "error";
	CSS.addClass(errorDiv, "error");
	set_inner_html(errorDiv, _tx("This stream is unavailable at this time. Please try again soon."));
	var newDiv = document.createElement("div");
	newDiv.id = "feed_error_wrapper";
	newDiv.appendChild(errorDiv);
	this.updateWrapper(location, newDiv, false);
	return;
};
HomeFeed.prototype.removeStoryStatusMessage = function () {
	var error_div = (ge("error") || ge("standard_status"));
	if (error_div) {
		error_div.parentNode.removeChild(error_div);
	}
};
HomeFeed.prototype.updateWrapper = function (location, element, animate) {
	var wrapperEl = $("newsfeed_wrapper");
	if (location == HomeFeed.LOC_APPEND) {
		wrapperEl.appendContent(element);
	} else {
		if (location == HomeFeed.LOC_PREPEND) {
			wrapperEl.prependContent(element);
			var startColor = "#FFF9D7";
			var pauseColor = "#FFFBE7";
			if (animate) {
				animation(element).to("background", startColor).from(startColor).to("height", "auto").from(0).ease(animation.ease.both).show().duration(500).to("opacity", 0).from(0).checkpoint().to("opacity", 1).from(0).ease(animation.ease.both).duration(750).checkpoint().to("background", pauseColor).from(startColor).duration(5000).checkpoint().duration(20000).checkpoint().to("background", "#fff").from(pauseColor).duration(5000).go();
			} else {
				show(element);
			}
		} else {
			wrapperEl.setContent(element);
		}
	}
	return this;
};
HomeFeed.prototype.banUser = function (app_id, banned_user, story_key) {
	var data = {"app_id":app_id, "banned_user":banned_user};
	var removeStoryHandler = function (asyncReponse) {
		var story = ge("div_story_" + story_key);
		if (story) {
			story.parentNode.removeChild(story);
		}
	};
	var errorHander = function (asyncResponse) {
		aiert("Could not ban this user");
	};
	var async = new AsyncRequest().setMethod("POST").setData(data).setHandler(bind(this, removeStoryHandler)).setErrorHandler(bind(this, errorHander)).setURI("/ajax/live_feed_ban.php").send();
	return this;
};
HomeFeed.prototype.updateStoriesHTML = function (html, story_class, location) {
	this.newStoriesClass = story_class;
	if (typeof (location) == "undefined") {
		location = HomeFeed.LOC_APPEND;
	}
	var newDiv = document.createElement("div");
	set_inner_html(newDiv, html);
	newDiv.style.overflow = "hidden";
	CSS.addClass(newDiv, story_class);
	this.updateWrapper(location, newDiv, false);
};
onloadRegister(function () {
	var fn = function () {
		var inst = HomeFeed.getInstance();
		if (inst) {
			inst.resetRefreshCount();
			inst.setAutoRefresh(inst.autoRefresh);
		}
	};
	window.onfocus = chain(window.onfocus, fn);
	window.onclick = chain(window.onclick, fn);
	window.onmouseover = chain(window.onmouseover, fn);
});
if (window.Bootloader) {
	Bootloader.done(["js/homefeed.js"]);
}

